//
//  LessondetailViewController.m
//  ThePrivateKitchen
//
//  Created by lirui on 16/1/23.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "LessondetailViewController.h"

@interface LessondetailViewController ()<UITableViewDataSource,UITableViewDelegate,UIWebViewDelegate>
@property(nonatomic ,retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *dataArr;
@property(nonatomic,retain)UIWebView *wv;
@property (nonatomic, retain) UIActivityIndicatorView *activity;
@property(nonatomic,assign)CGFloat height;
@end

@implementation LessondetailViewController
- (void)dealloc
{
    [_tableView release];
    [_dataArr release];
    [_wv release];
    [super dealloc];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
       }
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[ UIColor whiteColor];
    
    
    [self post];
    [self createActivity];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"left@3x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
    
}
-(void)leftAction:(UIBarButtonItem *)left
{
    [self.navigationController popViewControllerAnimated:YES];
}




-(void)post
{
    NSString *str =[ NSString stringWithFormat:@"http://h5.izhangchu.com/micro/shike.php?&material_id=%@",self.model.series_id];
    
    
    self.wv = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH *375, HEIGHT *667)];
    /**<  取消回弹效果 */
    self.wv.scrollView.bounces = NO;
//    
//   self.wv.scrollView.showsHorizontalScrollIndicator = NO;
//     self.wv.scrollView.scrollEnabled = NO;
    
    self.wv.delegate = self;
    [self.wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:self.wv];
  //  [self.wv release];
    
    
}

- (void) createActivity
{
    self.activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.activity.color = [UIColor grayColor];
    self.activity.center = self.view.center;
    [self.view addSubview:self.activity];
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [self.activity startAnimating];
   
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self.activity stopAnimating];

    _height = [[self.wv stringByEvaluatingJavaScriptFromString:@" document.body.scrollHeight;"] floatValue];
    

}


-(void)data
{
     NSString *str = [NSString stringWithFormat: @"http://api.izhangchu.com/?relate_id=%@&methodName=CommentList&size=20&page=1&type=2&version=4.3&",self.model.user_id];
[LRAFNetwork postUrlString:str body:nil response:JSON bodyStyle:RequestJSON requestHeadFile:nil success:^(NSURLSessionDataTask *task, id responseObject) {
    NSArray *arr = responseObject[@"data"][@"data"];
    self.dataArr = [ LessonModel modelHanderWithArray:arr];
    NSLog(@"~~~~~~~~%@",_dataArr);
    [_tableView reloadData];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
    
}];
    
    
}
-(void)creat
{
    self.tableView = [[ UITableView alloc] initWithFrame:CGRectMake(0, 0 , WIDTH *375, HEIGHT *667) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate  = self;
    _tableView.backgroundColor = [UIColor whiteColor];
    [_tableView registerClass:[LessonDetailTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.wv addSubview:_tableView];
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LessonDetailTableViewCell *cell = [ tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    LessonModel *m = _dataArr[indexPath.row];
    cell.name .text = m.nick;
    [cell.head sd_setImageWithURL:[NSURL URLWithString:m.head_img]];
    cell.time.text = m.create_time;
    cell.content.text= m.content;
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100 *HEIGHT;
}
-(void)creatheadView
{
    UIView *headview = [[ UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH *475, HEIGHT *667 - 200)];
    headview.backgroundColor = [UIColor redColor];
    self.tableView.tableHeaderView = headview;
    
    UIImageView  *img = [[ UIImageView alloc] initWithFrame:CGRectMake(0, 0,WIDTH *375 , headview.frame.size.height - 200)];
    img.backgroundColor = [UIColor greenColor];
    [headview addSubview:img];
    [img release];
   
    UILabel *textLabel =[[ UILabel alloc] initWithFrame:CGRectMake(0, headview.frame.size.height - img.frame.size.height,WIDTH *375, headview.frame.size.height - img.frame.size.height)];
    textLabel.backgroundColor= [ UIColor yellowColor];
    [headview addSubview:textLabel];
    [textLabel release];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
